import axios from 'axios'
import URL from './baseUrl'
import { Toast } from 'vant'

// 创建一个单例（实例）
const service = axios.create({
    baseURL:'apis',
    timeout: 5000
})

// 请求拦截
service.interceptors.request.use(
    config => {
        // if (!config.headers['X-Litemall-Token']) { //带上token信息
        //   config.headers['X-Litemall-Token'] = `${window.localStorage.getItem(
        //     'Authorization'
        //   ) || ''}`;
        // }
        Toast.loading({
            message: '加载中...',
            forbidClick: true,
        });
        return config;
    },
    err => Promise.reject(err)
)

// 响应拦截
service.interceptors.response.use(res => {
    Toast.clear();
    return res.data
}, err => {
    return Promise.reject(err);
});

export default service